@use 'sass:map';

@use './shared' as *;
@use './design' as *;

$wheel: () !default;
$wheel: map.merge(
  (
    b-color: get-css-var('border-color-base'),
    b-color-hover: get-css-var('color-primary-opacity-1'),
    b-color-focus: get-css-var('wheel-b-color-hover'),
    b-color-disabled: get-css-var('border-color-light-2'),
    item-v-padding: 3px,
    item-h-padding: 8px,
    item-opacity: 50%,
    item-opacity-active: 100%,
    item-color-active-hover: get-css-var('color-primary-opacity-1'),
    item-color-disabled: get-css-var('content-color-disabled'),
    arrow-color: get-css-var('content-color-secondary'),
    arrow-color-hover: get-css-var('content-color-base'),
    arrow-color-disabled: get-css-var('content-color-disabled'),
    arrow-size: 15px,
    mask-bg-color: transparent,
    mask-bg-color-hover: get-css-var('color-primary-opacity-8'),
    mask-bg-color-focus: get-css-var('wheel-mask-bg-color-hover')
  ),
  $wheel
);

.#{$namespace}-wheel {
  &-vars {
    @include define-preset-values('wheel', $wheel);
  }

  @mixin define-wheel-style($style-map) {
    @include define-preset-style('wheel', $style-map);
  }

  @include basis;

  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  outline: 0;

  &--horizontal {
    flex-direction: row;
  }

  &--disabled {
    cursor: not-allowed;
  }

  &__scroll {
    position: relative;
    cursor: pointer;
    user-select: none;
    border: get-css-var('border-shape') transparent;
  }

  &--loading &__scroll {
    cursor: auto;
  }

  &__list {
    display: flex;
    flex-direction: column;
    padding: 6px;
    margin: 0;
  }

  &--horizontal &__list {
    flex-direction: row;
  }

  &__item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: get-css-var('wheel-item-v-padding') get-css-var('wheel-item-h-padding');
    list-style: none;
    opacity: get-css-var('wheel-item-opacity');
    transition: get-css-var('transition-color'), get-css-var('transition-opacity');

    &--active {
      opacity: get-css-var('wheel-item-opacity-active');
    }

    &--disabled {
      color: get-css-var('wheel-item-color-disabled');
    }
  }

  &:hover &__item {
    &--active {
      color: get-css-var('wheel-item-color-active-hover');
    }

    &--disabled {
      color: get-css-var('wheel-item-color-disabled');
    }
  }

  &--disabled &__item {
    color: get-css-var('wheel-item-color-disabled');
  }

  &__arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: get-css-var('wheel-arrow-size');
    color: get-css-var('wheel-arrow-color');
    cursor: pointer;
    user-select: none;
    transition: get-css-var('transition-color');

    &:hover {
      color: get-css-var('wheel-arrow-color-hover');
    }

    &--disabled {
      &,
      &:hover {
        color: get-css-var('wheel-arrow-color-disabled');
        cursor: not-allowed;
      }
    }
  }

  &--horizontal &__arrow {
    width: get-css-var('wheel-arrow-size');
    height: 100%;
  }

  &__mask {
    position: absolute;
    pointer-events: none;
    background-color: get-css-var('wheel-mask-bg-color');
    opacity: 40%;
    transition: get-css-var('transition-background'), get-css-var('transition-border');
  }

  &:hover:not(#{&}--disabled) &__mask {
    background-color: get-css-var('wheel-mask-bg-color-hover');
  }

  &:focus:not(#{&}--disabled) &__mask {
    background-color: get-css-var('wheel-mask-bg-color-focus');
  }

  $border-width: get-css-var('wheel-mask-b-width');

  &--vertical &__mask {
    inset-inline-end: 0;
    inset-inline-start: 0;

    &--top {
      top: 0;
      border-bottom-width: $border-width;
    }

    &--bottom {
      bottom: 0;
      border-top-width: $border-width;
    }
  }

  &--horizontal &__mask {
    top: 0;
    bottom: 0;

    &--top {
      inset-inline-start: 0;
      border-inline-end-width: $border-width;
    }

    &--bottom {
      inset-inline-end: 0;
      border-inline-start-width: $border-width;
    }
  }

  $unit-size: 16px;

  &__border {
    @include h-moving-border(get-css-var('wheel-b-color'));

    position: absolute;
    pointer-events: none;
    border: get-css-var('border-shape') get-css-var('wheel-b-color');
    transition: get-css-var('transition-border');

    &--vertical {
      @include v-moving-border(get-css-var('wheel-b-color'));

      position: absolute;
    }

    &::before,
    &::after {
      opacity: 0%;
    }

    &--active {
      &::before,
      &::after {
        opacity: 100%;
      }
    }
  }

  &:hover:not(#{&}--disabled) &__border {
    &,
    &::before,
    &::after {
      border-color: get-css-var('wheel-b-color-hover');
    }
  }

  &:focus:not(#{&}--disabled) &__border {
    &,
    &::before,
    &::after {
      border-color: get-css-var('wheel-b-color-focus');
    }
  }

  &--disabled &__border {
    border-color: get-css-var('wheel-b-color-disabled');
  }

  $states: success, error, warning;

  @each $state in $states {
    &--#{$state} {
      @include define-wheel-style(
        (
          b-color: 'color' $state 'opacity-1',
          b-color-hover: 'color' $state 'opacity-1',
          mask-bg-color: 'color' $state 'opacity-8',
          mask-bg-color-hover: 'color' $state 'opacity-8',
          arrow-color: 'color' $state 'opacity-3',
          arrow-color-hover: 'color' $state 'base',
          arrow-color-disabled: 'color' $state 'opacity-6'
        )
      );
    }
  }
}
